﻿using System;

namespace Beeflys
{
    public delegate void MessengerOpencodeStatus(ActorOpencode opencode);

    public sealed class MessengerOperator<TMessenger> : IMessengerOperator<TMessenger>, IMessengerOperatorSetter
        where TMessenger : IActorMessengerDefine
    {
        internal MessengerOperator(IActorRef target, IActorRef source, TimeSpan timeout)
        {
            // var reqFunc = MessengerTable.GetMessengerReqBuilder(typeof(TMessenger));
            // if (reqFunc == null)
            // {
            //     throw new Exception();
            // }
            //
            // AMessengerReqWrap messengerReqWrap = reqFunc(target, source, timeout, opencode =>
            // {
            //     this.opencode = opencode;
            // });
            //
            // if (messengerReqWrap is TMessenger messenger)
            // {
            //     this.messenger = messenger;
            // }
        }

        private TMessenger messenger;

        private volatile ActorOpencode actorOpencode;
        private volatile MessengerOpencode messengerOpencode;

        public TMessenger Messenger
        {
            get { return this.messenger; }
        }

        public ActorOpencode ActorOpencode
        {
            get { return this.actorOpencode; }
        }

        public MessengerOpencode MessengerOpencode
        {
            get { return messengerOpencode; }
        }

        public void SetActorOpencode(ActorOpencode opencode)
        {
            this.actorOpencode = opencode;
        }

        public void SetMessengerOpencode(MessengerOpencode opencode)
        {
            this.messengerOpencode = opencode;
        }
    }
}